package com.itheima.pojo;

import java.util.List;

/**
 * 用于封装分页查询依赖的数据信息
 */
public class PageBean<T> {
    private List<T> list; //当前页展示的数据信息
    private int currentPage; // 当前页页码(上一页,下一页)
    private int pageSize; // 每页显示条数
    private int totalCount; // 总条数
    private int totalPage; // 总页数(计算)

    @Override
    public String toString() {
        return "PageInfo{" +
                "list=" + list +
                ", currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                '}';
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * 对总页数进行计算
     *      总页数计算时需要依赖 总条数和每页显示条数
     */
    public int getTotalPage() {
        // 总页数 = (总条数/每页显示条数)
        double page = Math.ceil(totalCount*1.0 / pageSize);
        return (int)page;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public PageBean() {
    }
}
